from django.http import HttpResponse, JsonResponse
from django.shortcuts import render

# Create your views here.
from apps.usermanager.controller import *
# from comment.errorcode import ErrorCodes
from utils.responseutils import format_response, RESP_TITLE, err_response


@format_response
def user(request):
    active = request.GET.get("active")
    try:
        params = json.loads(request.body)
        response_active = {
            "info": user_info,
            "list": user_list,
            "authorInfo": author_info,
            "login": login,
            "logout": logout,
            "signIn": sign_in,
            "search": user_search,
            "edit": user_edit,
            "collect": follow_user,
            "collects": user_collects,
            "follow": user_follows,
        }.get(active)(request,params)
    except Exception as e:
        logging.error(e)
        return err_response(RESP_ERR, "响应为空")
    if response_active is None:
        return err_response(RESP_ERR, "响应为空")
    resp = dict(zip(RESP_TITLE, response_active))
    return JsonResponse(resp)
